/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = giop_reply_v2.c                                   */
/*  NOTE      =                                                    */
/*  DATE      = 2015/12/18 by geyh                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include <corba/corba_comm.h>
#include <corba/corba_core.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"
#include "apmtest_cunit.h"
#include "apmtest_comm.h"

#include "../../../src/module/corba/config.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

extern int giop_reply_v2(Frbyte_Packet *p_st_data, Frreport_body_data *p_st_body_data, L7session_corba_private *p_st_private);

extern L7session_corba_private* __corba_private_create(void);
extern int __corba_private_destroy(L7session_corba_private **pp_st_private);

extern corba_session* __corba_session_create(void);


static void __case1(void)
{
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    corba_session *p_st_session_private = NULL;
    L7session_corba_private *p_st_private = NULL;
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, corba_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    p_st_session_private = __corba_session_create();
    p_st_private = __corba_private_create();
    p_st_session_private->p_st_private = p_st_private;
    p_st_private->i_endianess = 1;

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,(char *)"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x3c\x00\x00\x00\x3c\xaf"
            "\xab\xcb\x00\x00\x00\x00\x22\x00\x00\x03\xe8\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x08"
            "\x52\x6f\x6f\x74\x50\x4f\x41\x00\x00\x00\x00\x0c\x4e\x61\x6d\x65\x53\x65\x72\x76\x69\x63\x65\x00\x00\x00\x00"
            "\x03\x4e\x43\x30\x14", 80);

    i_ret = giop_reply_v2(p_st_data, p_st_body_data, p_st_session_private->p_st_private);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    bytebuff_free(&p_st_data);
    frreport_body_free(&p_st_body_data);
    __corba_private_destroy(&p_st_session_private->p_st_private);
    corba_session_destroy(p_st_session_private);
    apmtest_destroy_ct(&p_st_conn);
    return;

}


static void __case2(void)
{
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    L7session_corba_private *p_st_private = NULL;
    corba_session *p_st_session_private = NULL;
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, corba_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    p_st_session_private = __corba_session_create();
    p_st_private = __corba_private_create();
    p_st_session_private->p_st_private = p_st_private;
    p_st_private->i_endianess = 1;

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,(char *)"\x00\x00\x00\x04\x67\x65\x74", 7);

    i_ret = giop_reply_v2(p_st_data, p_st_body_data, p_st_session_private->p_st_private);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    bytebuff_free(&p_st_data);

    frreport_body_free(&p_st_body_data);
    __corba_private_destroy(&p_st_session_private->p_st_private);
    corba_session_destroy(p_st_session_private);
    apmtest_destroy_ct(&p_st_conn);
    return;

}


int add_suite_giop_reply_v2(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" giop_reply_v2()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
//    CU_add_test(pSuite, "case3", __case3);
//    CU_add_test(pSuite, "case4", __case4);

    return FR_SUCC;

}


